<template>
  <div>
    <!--编辑推荐-->
    <div class="wrap">
      <div class="title">编辑推荐</div>
      <div class="content">
        <van-row gutter="20">
          <van-col span="8" v-for="item in list" :key="item.id">
            <div class="item">
              <router-link :to="'/playlist/'+item.id">
                <img :src="item.picUrl" alt="">
                <div class="total">{{ formatPlayCount(item.playCount) }}</div>
                <div class="info">{{ item.name }}</div>
              </router-link>
            </div>
          </van-col>
        </van-row>
      </div>
    </div>
    <!--最新音乐-->
    <div class="main">
      <div class="title">最新音乐</div>
      <div class="list">
        <div v-for="item in newSong" :key="item.id">
          <router-link :to="{name:'songpage',params:{id:item.id,name:item.name}}" class="list-item">
            <div class="left">
              <div class="subtitle">{{ item.name }}<span> {{ item.song.alias[0] }}</span></div>
              <div class="author">
              <span v-for="ele in item.song.artists" :key="ele.id" class="ele">
                 {{ ele.name }}
              </span>
                - {{ item.song.album.name }}
              </div>
            </div>
            <div class="right">
              <img src="@/assets/images/play.png">
            </div>
          </router-link>
        </div>
        <!--        <div class="list-item">-->
        <!--          <div class="left">-->
        <!--            <div class="subtitle">歌曲名称<span>xxx</span></div>-->
        <!--            <div class="author">作者</div>-->
        <!--          </div>-->
        <!--          <div class="right">aa</div>-->
        <!--        </div>-->
      </div>
    </div>
  </div>
</template>

<script>
import songPage from '@/views/SongPage.vue'

export default {
  computed: {
    songPage () {
      return songPage
    }
  },
  data () {
    return {
      list: [], //编辑推荐数据
      newSong: [],//最新音乐列表数据
      authors: '', //作者名称
    }
  },
  // 进入页面获取网络请求---生命周期函数----
  created () {
    this.getMusic()
    this.getNewSong()
  },
  methods: {
    //获取推荐音乐数据-----
    async getMusic () {
      let res = await this.$api.getMusic()
      console.log('推荐音乐', res.data.result)
      this.list = res.data.result
    },
    //获取最新音乐--------
    async getNewSong () {
      let res = await this.$api.getNewSong()
      console.log('最新音乐', res.data.result)
      this.newSong = res.data.result
      //作者名称
    },
    //处理播放量的数据格式
    formatPlayCount (playCount) {
      if (playCount < 10000) {
        return playCount
      } else {
        return (playCount / 10000).toFixed(1) + '万'
      }
    },
    //过滤器
    filter: {
      sliceLine (val) {
        if (!val) return
        return val.slice(0, -1)
      }
    }

  }
}
</script>

<style scoped lang="less">
.title {
  margin-top: 0.2rem;
  margin-bottom: 0.2rem;
  font-size: 0.34rem;
  position: relative;
  padding-left: 0.2rem;

  &::before {
    content: "";
    position: absolute;
    width: 2px;
    height: 20px;
    top: 2px;
    background: #ff5555;
    left: 0;

  }
}

.content {
  .item {
    position: relative;

    img {
      width: 100%;
    }

    .total {
      color: #fff;
      position: absolute;
      right: 2px;
      top: 2px;
    }

    .info {
      margin: .14rem;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      text-overflow: ellipsis;
      overflow: hidden;
    }
  }

  .van-col {
    height: 3.56rem;
  }
}

//最新音乐
.list-item {
  border-bottom: 1px solid #eee;
  font-size: 17px;
  padding-top: 6px;
  padding-bottom: 6px;
  display: flex;

  .left {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;
  }

  .right {
    width: .9rem;
  }

  .subtitle {
    font-size: 17px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;

    span {
      //font-size: 12px;
      color: #888;
    }


    .subtitle {
      font-size: 17px;

      span {
        font-size: 12px;
        color: #888;
      }
    }
  }

  .author {
    margin-top: 4px;
    font-size: 14px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;

    .ele {
      &::after {
        content: '/';
      }
    }

    .ele:last-child {
      &::after {
        content: '';
      }
    }
  }
}
</style>
